Skip to content

[FIX] Division for zero quotient with either a negative divisor or dividend#246

Open
jmalovera10 wants to merge 5 commits intoelixirmoney:masterfrom
jmalovera10:fix/division-for-zero-quotient-with-either-a-divisor-or-dividend-negative
Open

[FIX] Division for zero quotient with either a negative divisor or dividend#246
jmalovera10 wants to merge 5 commits intoelixirmoney:masterfrom
jmalovera10:fix/division-for-zero-quotient-with-either-a-divisor-or-dividend-negative

Conversation

@jmalovera10
Copy link

@jmalovera10 jmalovera10 commented Sep 25, 2025

What is done?

This PR aims to solve the issue #236. It handles the case in which either the divisor or the dividend are negative and the value is 0 and dividend < divisor which results in a division under the current currency precision. To illustrate the change, here is an example of the behavior before:

iex(3)> Money.divide(Money.new(-3, :EUR), 5) # Does not add up to -3
[
  %Money{amount: 1, currency: :EUR},
  %Money{amount: 1, currency: :EUR},
  %Money{amount: -1, currency: :EUR},
  %Money{amount: 0, currency: :EUR},
  %Money{amount: 0, currency: :EUR}
]

And the behavior after:

iex(3)> Money.divide(Money.new(-3, :EUR), 5) # Adds up to -3
[
  %Money{amount: -1, currency: :EUR},
  %Money{amount: -1, currency: :EUR},
  %Money{amount: -1, currency: :EUR},
  %Money{amount: 0, currency: :EUR},
  %Money{amount: 0, currency: :EUR}
]

Also more thorough tests are added on negative values division to ensure proper behavior.

jmalovera10 and others added 5 commits September 24, 2025 20:07
* Fix the case when just one from the dividend and divisor is negative and the quotient is 0 with a remainter greater than 0
…-dividend-negative' of https://github.com/jmalovera10/money into fix/division-for-zero-quotient-with-either-a-divisor-or-dividend-negative
@jmalovera10 jmalovera10 changed the title Fix/division for zero quotient with either a divisor or dividend negative [FIX] Division for zero quotient with either a negative divisor or dividend Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant